home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 14642 / 14642.xpi / chrome / modules / trackers / wikipedia.js < prev   
Text File  |  2009-10-19  |  2KB  |  64 lines

  1. /* Copyright 2009, Boomtango.com.  All Rights Reserved. */
  2. /* wikipedia.js
  3.  * Responsible for tracking wikipedia articles
  4.  */
  5.  
  6. var EXPORTED_SYMBOLS = ["wikipedia"];
  7.  
  8. var wikipedia = {
  9.     name: "Wikipedia",
  10.     name_plural: "Wikipedia Entries",
  11.     color: "#333",
  12.     isInternal: true,
  13.     preview: function(doc, node, data){
  14.         if(data.preview){
  15.             var result = this.json.decode(data.preview);
  16.             var len = result.length;
  17.             var box = doc.createElement('vbox');
  18.             box.className = "wikipediabox";
  19.             if(len){
  20.                 for(var x = 0; x < len; x++){
  21.                     var item = result[x];
  22.                     
  23.                     var desc = doc.createElement("description");
  24.                     desc.className = "wikipedia";
  25.                     desc.appendChild(doc.createTextNode(item));
  26.                     box.appendChild(desc);
  27.                 }
  28.             }
  29.             node.appendChild(box);
  30.         }
  31.     },
  32.     onLoadTracks: function(url, doc){
  33.         var result = [];
  34.         if(doc && this.pattern.exec(url)){
  35.             var name = doc.getElementById("firstHeading").textContent;
  36.             var data = [];
  37.             var div = doc.getElementById("bodyContent");
  38.             if(div){
  39.                 var len = div.childNodes.length;
  40.                 for(var x= 0; x < len;x++){
  41.                     var item = div.childNodes[x];
  42.                     if(item.tagName == 'P'){
  43.                         data.push(item.textContent);
  44.                     } else if(item.id == 'toc'){
  45.                         break;
  46.                     }
  47.                 }
  48.  
  49.                 result.push(
  50.                     {
  51.                         type: "wikipedia",
  52.                         title: name,
  53.                         preview: this.json.encode(data)
  54.                     }
  55.                 );
  56.             }
  57.         }
  58.         return result;
  59.     },
  60.     json: Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON),
  61.     pattern: /^http(s*):\/\/(.*).wikipedia.org\/wiki\//
  62.  
  63. };
  64.